package com.funong.matrix.core.utils;

import java.util.List;

/**
 * @author NaNa
 * @since 2020-06-15 18:00
 */
public class PageUtil {
    /**
     * 手动分页
     *
     * @param sourceList
     * @param pageSize
     * @param pageNumber
     * @return
     */
    public static <T> List<T> convertPageList(List<T> sourceList, int pageSize, int pageNumber) {
        if (pageNumber == 0) {
            pageNumber = 1;
        }
        int size = sourceList.size();
        if (size <= pageNumber) {
            return sourceList;
        }
        int pageCount = size / pageSize + (size % pageSize == 0 ? 0 : 1);
        return sourceList.subList((pageNumber - 1) * pageSize, pageNumber < pageCount ? pageNumber * pageSize : size);
    }
}
